//
// GPSMapEdit
// (c) Konstantin Galichsky (kg@geopainting.com), 2003-2006
//
// The Holux-specific coordinate grid.
//

# include "StdAfx.h"
# include "HoluxRound.h"
# include "PtAlgo.h"
# include "Map.h"
# include "fast_floor.h"
# include "Globals.h"

float HoluxLatGrid (const map_t & _map, size_t _cLevelIdx) {
	return c_fHoluxCell*40000000./360;
}

void HoluxRoundPoint (const map_t & _map, size_t _cLevelIdx, point_t & _pt) {
	if (! g_bEnableSnapToGrid)
		return;

	_pt.x = c_fHoluxCell*(fast_floor (_pt.x*c_iHoluxCellInv + .5f));
	_pt.y = c_fHoluxCell*(fast_floor (_pt.y*c_iHoluxCellInv + .5f));
}

void HoluxRoundRect (const map_t & _map, size_t _cLevelIdx, rect_t & _rect) {
	if (! g_bEnableSnapToGrid)
		return;

	_rect.x0 = c_fHoluxCell*(fast_floor (_rect.x0*c_iHoluxCellInv + .5f));
	_rect.x1 = c_fHoluxCell*(fast_floor (_rect.x1*c_iHoluxCellInv + .5f));
	_rect.y0 = c_fHoluxCell*(fast_floor (_rect.y0*c_iHoluxCellInv + .5f));
	_rect.y1 = c_fHoluxCell*(fast_floor (_rect.y1*c_iHoluxCellInv + .5f));
}

void HoluxRoundPoints (const map_t & _map, size_t _cLevelIdx, points_t & _points) {
	if (! g_bEnableSnapToGrid)
		return;

	const size_t cPoints = _points.size ();
	for (size_t cPoint = 0; cPoint < cPoints; ++ cPoint) {
		point_t & pt = _points [cPoint];

		pt.x = c_fHoluxCell*(fast_floor (pt.x*c_iHoluxCellInv + .5f));
		pt.y = c_fHoluxCell*(fast_floor (pt.y*c_iHoluxCellInv + .5f));
	}
}
